/*
 *  BuyTest.cpp
 *  SpaceTrader
 *
 *  Created by Andrew on 11/19/12.
 *  Copyright 2012 The Hex Pistols. All rights reserved.
 *
 */

#include "BuyTest.h"

CPPUNIT_TEST_SUITE_REGISTRATION(BuyTest);

void BuyTest::setUp(){
    player = new Player();
	player->setCredits(1000);
}

void BuyTest::reset(){
	delete player;
	player = new Player();
	player->setCredits(1000);
}

void BuyTest::tearDown(){
    free(player);
}

void BuyTest::testIdealBuy() {
	bool ret;
	ret = player->buy(1,1,1);
	CPPUNIT_ASSERT(player->getInventory(1) == 1);
	CPPUNIT_ASSERT(player->getCredits() == 999);
	CPPUNIT_ASSERT(ret == true);
	ret = player->buy(1,2,2);
	CPPUNIT_ASSERT(player->getInventory(1) == 3);
	CPPUNIT_ASSERT(player->getCredits() == 995);
	CPPUNIT_ASSERT(ret == true);
	reset();
}

void BuyTest::testNotEnoughCredits() {
	bool ret =false;
	ret = player->buy(1,1001,1);
	CPPUNIT_ASSERT(player->getInventory(1) == 0);
	CPPUNIT_ASSERT(player->getCredits() == 1000);
	CPPUNIT_ASSERT(ret == false);
	reset();
}

void BuyTest::testNotEnoughSpace() {
	bool ret = false;
	ret = player->buy(1,1,30);
	CPPUNIT_ASSERT(player->getInventory(1) == 30);
	CPPUNIT_ASSERT(player->getCredits() == 970);
	CPPUNIT_ASSERT(ret == true);
	ret = player->buy(1,1,1);
	CPPUNIT_ASSERT(player->getInventory(1) == 30);
	CPPUNIT_ASSERT(player->getCredits() == 970);
	CPPUNIT_ASSERT(ret == false);
	reset();
}